home *** CD-ROM | disk | FTP | other *** search
- /*
- perspective bitmap sample code
-
- We will retreive a bitmap from the resource fork of this application. We will convert this bitmap into a bitmap
- shape. This shape will be drawn "normally" and it will be drawn perspected. We collect all of the images into one
- picture. The viewPort attached to the window will be set to a dither level of 4. This will make the drawing to a
- "gray" monitor look cool.
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "ColorLibrary.c", "GraphicsDebugLibrary.c",
- "MappingLibrary.c", "PictureLibrary.c",
- "QDLibrary.c", "ShapeLibrary.c", "TransformLibrary.c".
-
- • This file prints the "best" in landscape mode.
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Updated the note regarding the files needed to run.
- Updated the copyright date.
-
- ©1990 - 1996 Apple Computer, Inc.
- All rights reserved.
- */
-
- #include <Events.h>
- #include <Windows.h>
-
- #include <GXEnvironment.h>
- #include "GraphicsLibraries.h"
- #include <GXErrors.h>
- #include "QDLibrary.h"
- #include "graphics shell.h"
-
- //
- // Set up the title and size of the window
- //
- Rect gWindowQDRect = {40, 60, 250, 480};
- Str255 gWindowTitle = "\pPerspective Sample";
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 65k, I had 5 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- // If we were not dithering the viewPort attached to the window, we would need about 30k for the graphics gxHeap.
- //
- long gGraphicsHeapSize = 65;
-
- //
- // These gxPolygon structures are used to generate a perspective gxMapping:
- //
- long polyA[] = {4, ff(0), ff(0), ff(100), ff(0), ff(100), ff(100), ff(0), ff(100)}; // 100x100 upright
- long polyB[] = {4, ff(20), ff(20), ff(60), ff(-20), ff(110), ff(95), ff(5), ff(105)}; // offset & distorted
-
- gxShape updateShape;
-
-
-
- /*------ CreateImage -----------------------------------------------------------------------------------*/
-
- gxShape CreateImage(void);
- gxShape CreateImage()
- {
- gxShape bitsShape, shadowShape, image;
- gxTransform perspector;
- gxRectangle bounds;
- gxMapping polyMap;
-
- GXIgnoreGraphicsNotice (transform_already_set);
-
- image = GXNewShape(gxPictureType);
-
- //
- // Get the bitsShape from the resource file. If we do not get it, GXValidateShape will drop us into the debugger.
- //
- bitsShape = GetPixMapShape(128);
- GXValidateShape (bitsShape);
-
- GXGetShapeBounds(bitsShape, 0L, &bounds);
- shadowShape = GXNewRectangle(&bounds);
- GXMoveShape(shadowShape, ff(5), ff(5));
- GXSetShapeTransform(shadowShape, GXGetShapeTransform(bitsShape));
-
- AddToShape(image, shadowShape);
- AddToShape(image, bitsShape);
-
- PolyToPolyMap((gxPolygon *) &polyA, (gxPolygon *) &polyB, &polyMap);
- RotateMapping(&polyMap, ff(23), 0, 0);
-
- perspector = GXNewTransform();
- GXSetTransformMapping(perspector, &polyMap);
- GXMoveTransform(perspector, ff(265), ff(5));
-
- AddToPicture(image, shadowShape, nil, nil, perspector);
- AddToPicture(image, bitsShape, nil, nil, perspector);
-
- GXDisposeShape(shadowShape);
- GXDisposeShape(bitsShape);
- GXDisposeTransform(perspector);
-
- GXPopGraphicsNotice ();
-
- return image;
- }
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(theWindow)
- WindowPtr theWindow;
- {
- gxViewPort windowViewPortParent;
-
- //
- // Get the viewPort that is attached to the window, and set the dither of this viewPort to 4. Which
- // will mean that all objects that are drawn into window will be dithered at a dither level of 4.
- //
- windowViewPortParent = GXGetWindowViewPort(theWindow);
- GXSetViewPortDither(windowViewPortParent, 4);
-
- updateShape = CreateImage();
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(theWindow)
- WindowPtr theWindow;
- {
- GXDrawShape(updateShape);
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(theWindow)
- WindowPtr theWindow;
- {
- //
- // You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- // form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- // call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- // SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- // can turn notices on in this file by setting gDebugging = TRUE (above).
- //
- GXDisposeShape(updateShape);
- GXDisposeShape(gWindowBoundsShape);
- DisposeWindow(theWindow);
- }
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- }
-
-
- /*------ DoIdle -----------------------------------------------------------------------------------------*/
-
- void DoIdle(theWindow)
- WindowPtr theWindow;
- {
- }